package com.drug.controller;


import com.drug.domain.Result;
import com.drug.domain.User;
import com.drug.domain.UserR;
import com.drug.mapper.UserRoleMapper;
import com.drug.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private UserRoleMapper userRoleMapper;
    //多条件查询
    @ResponseBody
    @RequestMapping("/selectUser")
    public List<UserR> selectUser(UserR userR){
        return userRoleService.selectUser(userR);

    }

    //分页查询
    @RequestMapping("/selectUserAll")
    @ResponseBody
    public Result findAll(@RequestParam(required=true,defaultValue="1")Integer pageNum){
        return userRoleService.findAll(pageNum);
    }

    //逻辑删除
    @ResponseBody
    @RequestMapping("/deleteUser")
    public String deleteUser(Integer uId) {
        userRoleService.deleteUser(uId);
        return "drug userrole";
    }
    //新增
    @ResponseBody
    @RequestMapping("/insertUser")
    public void insertUser(UserR userR){ ;
        userRoleService.insertUser(userR);
    }
    //修改回显
    @ResponseBody
    @RequestMapping("/selectUserById")
    public User selectUserById(String uId){
        User user = userRoleMapper.selectUserById(Integer.valueOf(uId));
        System.err.println(user);
        return user;
    }
    //修改
    @ResponseBody
    @RequestMapping("/updateUser")
    public Result updateUser(UserR userR){
        Result result = new Result();
        System.err.println(userR);
        Integer integer = userRoleService.updateUser(userR);
        if (integer>=1){
            result.setMsg("");
        }
        return result;
    }

    //字典条件查询
    @ResponseBody
    @RequestMapping("/selectUserLeixing")
    public List<UserR> selectDictionaryUser(UserR userR){
        return userRoleService.selectUser(userR);
    }


}
